<template>
	<view class="mainbgc">
		<view class="mainpadding">
			<view class="titletext">选择充值金额</view>
			<view class="flexbetween flex_wrap margin_top">
				<view :class="index==current?'focusbgc':'focusbgc'" v-for="(item,index) in sellist" :key="index"
					@click="change(index,item.price)">
					<view class="itemlable" :class="index==current?' color':'colorbai '" @click="change">{{item.price}}元
					</view>
				</view>
			</view>
			<view class="mainpadding ffffff radius margin_top">
				<input type="text" placeholder="自定义充值金额" v-model="money">
			</view>
		</view>
		<!-- 支付方式 -->
		<view class="mainpadding ffffff radius margin_top">
			<view class="flexbetween">
				<view class="flexright">
					<view class="weixin margin_right1"></view>
					<view class="notitletext">微信</view>
				</view>
				<view class="weigouxuan"></view>
				<!-- 未选中 -->
				<!-- <view class="yigouxuan"></view> -->
			</view>
		</view>
		<view class="positionbottom mainpadding">
			<view class="flexcenter nostrongtext" @click="chongzhi">充值记录</view>
			<view class="bottombtn margin_top" @click.stop="recharge">立即充值</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				current: -1,
				sellist: {}, //充值列表
				pay_price: '',
				money:"",//自定义充值金额
			}
		},
		onShow() {
			this.getlist()
		},
		methods: {
			callPayMent() { //uni.requestPayment支付
				let _this = this;
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: _this.wxpay.timeStamp,
					nonceStr: _this.wxpay.nonceStr,
					package: _this.wxpay.package,
					signType: _this.wxpay.signType,
					paySign: _this.wxpay.paySign,
					success: function(res) {
						// 支付成功
						httpRequest.toast('支付成功')
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					},
					fail: function(err) {
						// 支付失败
						httpRequest.toast('支付失败')
					}
				});
			},
			recharge() { //余额充值
				let _this = this;
				if (_this.pay_price == '') {
					httpRequest.toast('请选择充值金额')
					return
				}
				httpRequest.request('/api/rechargeorder/rechargeMoney', 'POST', {
					pay_price: _this.pay_price
				}).then(res => {
					if (res.code == 1) {
						_this.wxpay = JSON.parse(res.data.wxconfig);
						_this.callPayMent();
					}
				})
			},
			getlist() { //充值项
				let _this = this;
				httpRequest.request('/api/Rechargeorder/rechargeItem', 'GET', {}).then(res => {
					if (res.code == 1) {
						_this.sellist = res.data;
					}
				})
			},
			chongzhi() {
				uni.navigateTo({
					url: "/pages/mypage/chongzhijl"
				})
			},
			change(index, id) {
				this.current = index;
				this.pay_price = id;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.itemlable {
		padding: 30rpx 0;
		text-align: center;
		width: 200rpx;
	}

	.focusbgc {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		background-color: #ffffff;
	}

	.color {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #228DFF;
		background-color: RGBA(233, 244, 255, 1);
		border: 2rpx solid #218dff;
	}

	.colorbai {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		background-color: #ffffff;
	}

	.nofocusbgc {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000;
		background-color: #fff;
		border: 1rpx solid #fff;
	}

	.positionbottom {
		position: fixed;
		bottom: 60rpx;
		left: 0;
		width: 100%;
		box-sizing: border-box;
	}

	.weixin {
		width: 32rpx;
		height: 32rpx;
		background-size: 100% 100%;
		background-image: url('../../static/images/system/weixin.png');
	}
</style>